<!-- 用户页面 音乐品味(喜欢的音乐) 卡片组件 -->
<template>
  <view>
    <view v-if="playlist.length" class="card-container">
      <view class="card-header">
        <view class="card-title">音乐品味</view>
      </view>
      <view class="card-list">
        <view class="list-item-container" @click="gotoInfo(`/pages/SongLists?id=${playlist[0].id}`,playlist[0].trackCount)">
          <view class="cover-item-container">
            <view class="cover-item">
              <view>
                <image :src="playlist[0].coverImgUrl" alt="" />
              </view>
            </view>
          </view>
          <view class="list-item-content">
            <view class="first-line">我喜欢的音乐</view>
            <view class="second-line">{{ playlist[0].trackCount }}首，播放{{ num(playlist[0].playCount) }}次</view>
          </view>
        </view>
      </view>
    </view>
   <view v-else class="empty-container">
      <view>
        <image src="https://p6.music.126.net/obj/wonDlsKUwrLClGjCm8Kx/13730292083/d52f/4cb8/04e3/3dac51a19e0aaa1a8ae2e764d624b0af.png" alt="" />
        <view class="tips">Ta很神秘，需要深入了解</view>
      </view>
    </view>
  </view>
</template>

<script>
import { userSongListAPI } from '@/api'
import { numberFormat } from '@/utils/common';
export default {
  data() {
    return {
      userId: '', //获取当前页面路由id值
      playlist: [], //用户歌单曲目
    }
  },
	computed: {
		//格式化数字
		num() {
			return (val) => {
				return numberFormat(val);
			};
		}
	},
  methods: {
    //获取用户歌单
    userSongList() {
      userSongListAPI({ uid: this.userId }).then((res) => {
        this.playlist = res.playlist
      })
    },
		gotoInfo(url,num) {
			if(num == '0'){
				return
			} else {
				uni.navigateTo({ url })
			}
		}
  },
}
</script>

<style lang="scss" scoped>
.card-container {
  display: flex;
  box-sizing: border-box;
  width: 100%;
  height: max-content;
  padding: 0 4.26666667vw;
  margin-top: 6.13333333vw;
  margin-bottom: 3.73333333vw;
  -webkit-box-orient: vertical;
  -webkit-box-direction: normal;
  flex-direction: column;
  background-color: #fff;
  .card-header {
    -webkit-box-pack: justify;
    justify-content: space-between;
    -webkit-box-align: center;
    align-items: center;
    margin-bottom: 1.86666667vw;
    display: flex;
    .card-title {
      font-weight: 600;
      font-size: 4.26666667vw;
      line-height: 5.06666667vw;
      color: #333;
    }
  }
  .card-list > view:not(:last-of-type) {
    margin-bottom: 1.86666667vw;
  }
  .list-item-container {
    width: 100%;
    min-height: 14.13333333vw;
    display: flex;
    -webkit-box-orient: horizontal;
    -webkit-box-direction: normal;
    flex-direction: row;
    -webkit-box-align: center;
    align-items: center;
    -webkit-box-pack: justify;
    justify-content: space-between;
    overflow: hidden;
    .cover-item-container {
      position: relative;
      z-index: 0;
      .cover-item,
      .cover-item > view {
        width: 13.33333333vw;
        height: 13.33333333vw;
        background-color: #b9b9b9;
        opacity: 1;
        border-radius: 2.13333333vw;
        position: relative;
      }
      .cover-item > view {
        overflow: hidden;
      }
      .cover-item > view > image {
        width: 100%;
        height: 100%;
        object-fit: cover;
      }
      .cover-item:before {
        position: absolute;
        content: ' ';
        border-radius: 2.13333333vw;
        background: #000;
        opacity: 0.05;
        width: 11.2vw;
        height: 11.2vw;
        top: -0.8vw;
        left: 50%;
        transform: translateX(-50%);
        z-index: -10;
      }
    }
    .list-item-content {
      -webkit-box-flex: 1;
      flex: 1;
      margin-left: 2.66666667vw;
      overflow: hidden;
      > view {
        max-width: 66.93333333vw;
        width: 100%;
        overflow: hidden;
        white-space: nowrap;
        text-overflow: ellipsis;
      }
      .first-line {
        font-weight: 400;
        font-size: 4.26666667vw;
        line-height: 5.06666667vw;
        color: #333;
      }
      .second-line {
        font-style: normal;
        font-weight: 400;
        font-size: 3.2vw;
        line-height: 3.73333333vw;
        color: #999;
        margin-top: 0.8vw;
      }
    }
  }
}
.empty-container {
  width: 100%;
  height: 100%;
  display: flex;
  -webkit-box-orient: vertical;
  -webkit-box-direction: normal;
  flex-direction: column;
  -webkit-box-pack: start;
  justify-content: flex-start;
  -webkit-box-align: center;
  align-items: center;
  padding-top: 14.66666667vw;
  > view > image {
    width: 45.33333333vw;
    height: 32vw;
    object-fit: contain;
  }
  .tips {
    margin-top: 4.8vw;
    font-style: normal;
    font-weight: 400;
    font-size: 3.73333333vw;
    line-height: 5.06666667vw;
    color: #999;
  }
}
</style>